package org.come.Jpanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.tool.time.Limit;
import com.tool.time.TimeLimit;
import com.tool.time.TimerUtil;
import com.updateNew.MyIsif;

import org.come.Frame.ZhuFrame;
import org.come.bean.PayvipBean;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;

import com.tool.btn.VipShopBtn;
import com.tool.tcpimg.UIUtils;

/**
 * HGC-2019-11-21 VIP商品面板
 * 
 * @author Administrator
 * 
 */
public class RechargeVIPGoodsJpanel extends JPanel {

	/**
	 * 领取按钮
	 */
	private VipShopBtn vipShopBtn;
	/**
	 * VIP阶段名称name<br>
	 * 
	 * 
	 */
	private String name = "V1会员奖励";
//	/** 描述 */
	private RechargeVIPJpanel rechargeVIPJpanel;
	/**
	 * 当前展示的物品
	 */
	
	private PayvipBean payvipBean;
	private JLabel jLabel;
	private Mlistener mlistener ;
	public RechargeVIPGoodsJpanel() {
		setPreferredSize(new Dimension(36, 20));
		setOpaque(false);
		setLayout(null);

		getVipShopBtn();
//		getRichLabel();
		mlistener= new Mlistener(payvipBean);
		this.addMouseListener(mlistener);
	}


	/**
	 * 展示物品
	 * 
	 * @param payvipBean
	 */
	public void showGoods(PayvipBean payvipBean) {
		this.payvipBean = payvipBean;
		if (payvipBean != null) {
			mlistener.setPayvipBean(payvipBean);
//			getIconVip().setImage(CutButtonImage.getImage("img/item/S" + (19 + payvipBean.getGrade()) + ".png", -1, -1).getImage());
			getIconGift().setImage(CutButtonImage.getImage("inkImg/old/background/gift-icon.png", -1, -1).getImage());

			name = "累充" + payvipBean.getPaynum() + "奖励";
		} else {
			vipShopBtn.setBtn(0);
		}
	}

	/**
	 * 对应物品
	 */
	public void exchangeGoods() {
		String sendmes = Agreement.getAgreement().VipgradesureAgreement("v" + payvipBean.getGrade());
		SendMessageUntil.toServer(sendmes);
	}

	/**
	 * 移入移出
	 * 
	 * @author Administrator
	 * 
	 */
	class Mlistener implements MouseListener {
		
		private PayvipBean payvipBean;
		

		public Mlistener(PayvipBean payvipBean) {
			this.payvipBean = payvipBean;
		}

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			//打开了窗体
			if(e.isMetaDown()){//检测鼠标右键单击
				FormsManagement.HideForm(3002);
			}else {
				if(payvipBean == null) {
                    return;
                }
				RechargeVIPJpanel.paintPeopleGoods(payvipBean);
				paintPeople();
			}
//			this.first_x = e.getX();
//			this.first_y = e.getY();
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub

		}

		@Override
		public void mouseEntered(MouseEvent e) {
			if(payvipBean == null) {
                return;
            }
			ZhuFrame.getZhuJpanel().creatgoodtext(payvipBean);
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			FormsManagement.HideForm(24);
		}

		public PayvipBean getPayvipBean() {
			return payvipBean;
		}

		public void setPayvipBean(PayvipBean payvipBean) {
			this.payvipBean = payvipBean;
		}
		

	}

	private ImageIcon iconBack;

	private ImageIcon iconGift, iconVip;

	@Override
	protected void paintComponent(Graphics g) {
		// TODO Auto-generated method stub
		super.paintComponent(g);
		if (payvipBean != null) {
//			if (iconBack == null) {
//				iconBack = CutButtonImage.getImage("inkImg/old/background/S3﻿.png", -1, -1);
//			}
//			g.drawImage(iconBack.getImage(), 0, 0, 136, 134, this);
			if (iconGift == null) {
				iconGift = CutButtonImage.getImage("img/item/S13.png", -1, -1);
			}
			g.drawImage(iconGift.getImage(), 20, 10, 69, 96, this);
//			if (iconVip == null) {
//				iconVip = CutButtonImage.getImage("img/item/S23.png", -1, -1);
//			}
//			g.drawImage(iconVip.getImage(), 10, 10, 30, 25, this);

			if (name != null) {
				g.setFont(UIUtils.TEXT_BOLD_FONT);
				g.drawString(name, 0, 110);
			}
		}
	}
	private ImageIcon icon2;
	public void paintPeople() {
//		icon2 = new ImageIcon("inkImg/old/background/S163.png");
//		jLabel = new JLabel();
//		jLabel.setIcon(icon2);
//		jLabel.setBounds(-5, 10, 150, 110);
//		this.add(jLabel);
	}
	public VipShopBtn getVipShopBtn() {
		if (vipShopBtn == null) {
			vipShopBtn = new VipShopBtn("inkImg/hongmu/1/lingqu.png", 1, 57, this);
			vipShopBtn.setBounds(20, 120, 65, 26);
			this.add(vipShopBtn);
		}
		return vipShopBtn;
	}

	public void setVipShopBtn(VipShopBtn vipShopBtn) {
		this.vipShopBtn = vipShopBtn;
	}

	public ImageIcon getIconBack() {
		return iconBack;
	}

	public void setIconBack(ImageIcon iconBack) {
		this.iconBack = iconBack;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}


	public ImageIcon getIconGift() {
		if (iconGift == null) {
			iconGift = new ImageIcon();
		}
		return iconGift;
	}

	public void setIconGift(ImageIcon iconGift) {
		this.iconGift = iconGift;
	}

	public ImageIcon getIconVip() {
		if (iconVip == null) {
			iconVip = new ImageIcon();
		}
		return iconVip;
	}

	public void setIconVip(ImageIcon iconVip) {
		this.iconVip = iconVip;
	}

	public PayvipBean getPayvipBean() {
		return payvipBean;
	}

	public void setPayvipBean(PayvipBean payvipBean) {
		this.payvipBean = payvipBean;
	}

	public Mlistener getMlistener() {
		return mlistener;
	}

	public void setMlistener(Mlistener mlistener) {
		this.mlistener = mlistener;
	}

}
